﻿@using Backend.JYD.Model;
@using Backend.JYD.Model.Task;
@using Backend.JYD.Business;
@using Backend.JYD.Common;
@using Backend.JYD.BLL;
@{
    ViewBag.Title = "任务提交";
    Layout = "~/Views/Shared/_LayoutWin.cshtml";
}
@using (Ajax.BeginForm("next", new AjaxOptions() { OnSuccess = "afterpost" }))
{
    <div class="ui_pop_body" style="width: 600px; height: 350px;">
        <div>
            <ul class="edit-ul">
            @{
                var nextModeles = this.ViewBag.NextModeles as List<TaskStepModel>;
                if (nextModeles != null && nextModeles.Count > 0)
                {
                    var manager = new RoleManager();
                     foreach (var info in nextModeles)
                     { 
                <li class="li03">
                    <span class="s01"><font color="red">*</font>选择提交步骤：</span>
                    <span class="s02">
                        <input type="radio" name="rdoStepId" id="@("rdoStepId" + info.StepId)" value="@info.StepId" title="@info.StepName"/>
                        <label for="@("rdoStepId" + info.StepId)">@info.StepName</label><br />
                        @if (info.UseRole)
                        {
                            var nextIds = StringHelper.String2List<Int64>(info.RoleIds);
                            var roles = manager.GetRoleInfoByRoleIds(nextIds);
                            if (roles != null)
                            {
                                foreach (var role in roles)
                                {
                        <input type="checkbox" name="chkId" id="@("chkRole" + role.RoleId)" value="@role.RoleId" title="@role.RoleName"/>
                        <label for="@("chkRole" + role.RoleId)">@role.RoleName</label><br />
                                }
                            }
                            else
                            {
                                @(new HtmlString("无"))
                            }
                        }
                        else
                        {
                            var nextIds = StringHelper.String2List<Int64>(info.RoleIds);
                            var emps = new EmpInfoBLL().GetEmpInfoByEmpIds(nextIds, false);
                            if (emps != null)
                            {
                                foreach (var emp in emps)
                                {
                        <input type="checkbox" name="chkId" id="@("chkEmp" + emp.EmpId)" value="@emp.EmpId" title="@emp.EmpName" />
                        <label for="@("chkEmp" + emp.EmpId)">@emp.EmpName</label><br />
                                }
                            }
                            else
                            {
                                @(new HtmlString("无"))
                            }
                        }
                       
                    </span>                    
                </li>
                     }
                }
            }
                <li class="li01" style="height:90px;">
                    <span class="s01">备注：</span>
                    <span class="s02">
                        <textarea name="remark" id="remark" rows="5" style="width:300px;"></textarea>
                    </span>
                </li>
                <li class="li01">
                    <span class="s01"></span>
                    <span class="s02">
                        <input type="submit" value="提交" onclick="return check()"/>
                        @*@Ajax.ActionLink("提交", "Process", new AjaxOptions { HttpMethod = "POST", OnSuccess = "afterpost" })*@
                        <input type="button" value="取消" onclick="closeWin()"/>
                        <input type="hidden" value="@this.ViewBag.TaskId" name="id" />
                    </span>
                </li>
            </ul>
        </div>
        <input type="hidden" value="@this.ViewBag.TaskId" name="hidTaskId"/>
    </div>
    <script src="@Url.Content("~/skin/js/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    <script type="text/javascript">
        function afterpost(data) {
            if (data.code) {
                closeWinAndReload();
            }
            else {
                alert(data.msg);

            }
        }

        function check() {
            if ($('input[name="rdoStepId"]').length > 0) {
                if (!$('input[name="rdoStepId"]:checked').val()) {
                    alert("选择执行步骤");
                    return false;
                }
            }
            if ($('input[name="chkId"]').length > 0) {
                if (!$('input[name="chkId"]:checked').val()) {
                    alert("选择执行人/角色");
                    return false;
                }
            }
            return true;
        }

    </script>
}


